package com.vo;

import com.alibaba.fastjson.JSONObject;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

@Data
public class FlowVo {

    /**
     * {
     *     "timestamp": 1658152564098414,
     *     "call_source": "",
     *     "source_name": "",
     *     "callid": "27d36dee-a03f-40d2-b92e-2872c9057c21",
     *     "appid": "451f16c4-6795-4976-a8c0-0f6c255dd9ac",
     *     "method": "create"
     * }
     */
    private String a;

    private String timestamp;//请求的时间戳
    private String call_source;//呼叫来源 ，比如队列外呼就是 queuedialer
    private String source_name;//来源名称 ，比如队列外呼就是任务名称
    private String callid;//通话唯一UUID
    private String appid;//执行动作的UUID，每次需要执行新动作系统会预先生成UUID，后续的输入都会带上这个UUID，动作执行完成时就会生成新的UUID。
    private String method;//

    /**
     * {
     *     "action": "cti_play_and_detect_speech",
     *     "argument": "'1' '32' '0' '0.3' 'down.ddrj.com:9988' '120' '800' '5000' '20000' '' '' '451f16c4-6795-4976-a8c0-0f6c255dd9ac' '1' '${strftime(%Y-%m-%d)}' 'wav'",
     *     "tts": {
     * 	"ttsurl": "http://down.ddrj.com:9989/tts",
     * 	"ttsvoicename": "",
     * 	"ttsconfig": "",
     * 	"ttsengine": "",
     * 	"ttsvolume": 0,
     * 	"ttsspeechrate": 0,
     * 	"ttspitchrate": 0
     *     },
     *     "privatedata": "test",
     *     "playbacks": [
     * 	"欢迎进入测试程序，被叫号码是",
     * 	"${destination_number}",
     * 	"请说话测试吧",
     * 	"test.wav"
     *     ],
     *     "sound_file_dir": "E:/sad/",
     *     "pre_tts_text": [
     * 	"徐先生",
     * 	"2022年12月6日"
     *     ],
     *     "log": "create succeed"
     * }
     */
    private String action;//执行的动作 cti_play_and_detect_speech 放音同时执行语音识别
    private String argument;//动作参数
    private String privatedata;
    private String sound_file_dir;
    private String log;
//    private tts tts;
    private List<String> playbacks;
    private List<String> pre_tts_text;


    /**
     * {
     *    "timestamp": 1658152582127483,
     *    "input_type": "text",
     *    "input_args": "F你好",
     *    "input_start_time": 1658152579338493,
     *    "input_duration": 2779,
     *    "play_progress": 0,
     *    "callid": "27d36dee-a03f-40d2-b92e-2872c9057c21",
     *    "appid": "1e89c6c7-e03b-4988-be0a-7eee25df8fa7",
     *    "method": "input",
     *    "privatedata": "test",
     *    "record": "C:/src/utility/freeswitch/x64/Debug/recordings/2022-07-18/27d36dee-a03f-40d2-b92e-2872c9057c21_1.wav"
     * }
     */
//    private String callid;
//    private String method;
//    private String privatedata;
//    private String timestamp;
    /**
     * input_type 输入类型
     *
     * text ASR
     * dtmf 按键
     * complete 动作执行完成
     */
    private String input_type;

    /**
     * input_args 输入参数，input_type TEXT时asr识别结果，DTMF时按键内容。COMPLETE是完成输入参数
     *
     * text：asr识别结果前缀说明
     * 前缀F：一句话识别完成
     * 前缀E：ASR错误
     * 前缀S：用户还在说话，实时识别中
     * 前缀b：检测到开始说话
     * dtmf:dtmf按键内容
     * d:未匹配到终止符
     * D:已经匹配到终止符
     * complete:完成输入参数
     * DONE() 输入完成,DONE(F:识别内容1F:识别内容2)
     * TIMEOUT() 输入超时了，TIMEOUT(F:放音时候的识别内容S:超过最大说话时间了)。如果没检测到声音就是TIMEOUT()。TIMEOUT(S:识别内容)这样的也代表一次ASR调用，也要对ASR进行计费。
     * ERROR() 遇到错误
     * BREAK() 外部程序执行了uuid_break
     */
    private String input_args;

    /**
     * input_start_time 输入开始时间，比如说话开始时的时间(微秒的时间戳)
     */
    private String input_start_time;

    /**
     * input_duration 输入持续时间 ，比如说话的持续时间（毫秒）
     */
    private String input_duration;
    /**
     * play_progress 当前的放音时间(毫秒)
     */
    private String play_progress;
    private String record;


    /**
     * {
     *    "action": "cti_play_and_detect_speech",
     *    "argument": "'1' '32' '0' '0.3' 'down.ddrj.com:9988' '120' '800' '5000' '20000' '' '' '8c44580b-ee09-4eaf-9641-d54c0466d810' '1' '${strftime(%Y-%m-%d)}' 'wav'",
     *    "privatedata": "test",
     *    "playbacks": [
     *        "机器人放音内容"
     *    ],
     *    "log": "自定义日志"
     * }
     */

    public static void main(String[] args) {
        Map<String,Object> flowMap=new TreeMap<>();
        flowMap.put("action","cti_play_and_detect_speech");
        flowMap.put("argument","'1' '32' '0' '0.3' 'http://127.0.0.1:9988' '120' '800' '5000' '20000' '' '' '{\"group\":\"default\"}' '1' '${strftime(%Y-%m-%d)}' 'wav'");
        //tts设置
        Map<String,String> ttsMap=new TreeMap<>();
        ttsMap.put("ttsurl","http://127.0.0.1:9989/tts");
        ttsMap.put("ttsvoicename","");
        ttsMap.put("ttsconfig","");
        ttsMap.put("ttsengine","");
        ttsMap.put("ttsvolume","");
        ttsMap.put("ttsspeechrate","");
        ttsMap.put("ttspitchrate","");
        flowMap.put("tts",ttsMap);

        List<String>  playbacksList=new ArrayList<>();
        playbacksList.add("欢迎你，请说话");
        flowMap.put("playbacks",playbacksList);

        flowMap.put("sound_file_dir","");//声音文件路径
        //回调参数
        flowMap.put("privatedata","回传参数");
        flowMap.put("quickresponse","false");

        List<String> pre_tts_text_list=new ArrayList<>();
        pre_tts_text_list.add("徐先生");
        flowMap.put("pre_tts_text",pre_tts_text_list);
        flowMap.put("log","create succeed");

        System.out.println(JSONObject.toJSONString(flowMap));

    }
}
